package com.pz.sjxypz;

/**
 * 定义数据源实现类
 */

import com.pub.dbtools.DBOperator;
import com.pub.dbtools.DBTools;
import com.pub.dbtools.DataGrid;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("sjxypzService")
@Transactional
public class sjxypzService implements sjxypzServiceI{

    public DataGrid getOneList(Map tmpMap) {
        String sPage = (String) tmpMap.get("page");
        String sRows = (String) tmpMap.get("rows");
        String sSort = (String) tmpMap.get("sort");
        String sOrder = (String) tmpMap.get("order");
        String sLxmc = (String) tmpMap.get("lxmc");

        int nrows = Integer.parseInt(sRows);
        if (nrows == 10) {
            nrows = 8;
        }
        int npage = Integer.parseInt(sPage);
        String sortorder = " ";
        if (sSort.equals("c_县市区")) {
            sortorder = " order by fd_xsq " + sOrder;
        }


        String selesql = " select pk_scld t_id,fd_xsq c_县市区,fd_xlbh c_线路编号,fd_xlmc c_线路名称, " +
                "fd_ldq c_路段起,fd_ldz c_路段止,fd_xlzls c_总里数,fd_gxldmc c_管辖名称,fd_gxldq c_管辖起," +
                "fd_gxldz c_管辖止,fd_gxls c_管辖里数,fd_zfga c_公安交警,fd_zfgafzr c_公安负责人及联系方式," +
                "fd_zflz c_高速路政,fd_zflzfzr c_高速负责人及联系方式,fd_zfjy c_经营单位,fd_zfjyfzr c_经营负责人及联系方式," +
                "fd_bgslx c_当地办公室联系方式,fd_ssdq c_所属地区,fd_bz c_备注 ";
        String fromsql = " from f_ld_scld";
        String withsql = "";
        String ordersql = sortorder;
        String groupsql = "";
        String wheresql = "";
        DBTools tmpdata = new DBTools();
        HashMap<String, String> hashmap = new HashMap<String, String>();
        hashmap.put("fd_WithSql".toLowerCase(), withsql);
        hashmap.put("fd_SearchSql".toLowerCase(), selesql);
        hashmap.put("fd_FromSql".toLowerCase(), fromsql);
        hashmap.put("fd_WhereSql".toLowerCase(), wheresql);
        hashmap.put("fd_OrderSql".toLowerCase(), ordersql);
        hashmap.put("fd_GroupSql".toLowerCase(), groupsql);



        int ntot = 0;
        long ltotNum = 0;
        List<Object> thisobj = null;
        ntot = DBOperator.countNum(fromsql, wheresql, ordersql, withsql,
                groupsql);
        thisobj = tmpdata.makePageList(hashmap, npage, nrows, ntot);
        ltotNum = (long) ntot;

        DataGrid dg = new DataGrid();
        dg.setRows(thisobj);
        dg.setTotal(ltotNum);
        return dg;
    }
    public DataGrid getTwoList(Map tmpMap) {
        String sPage = (String) tmpMap.get("page");
        String sRows = (String) tmpMap.get("rows");
        String sSort = (String) tmpMap.get("sort");
        String sOrder = (String) tmpMap.get("order");
        String onekeyid = (String) tmpMap.get("onekeyid");
        String  pno= (String) tmpMap.get("pno");

        int nrows = Integer.parseInt(sRows);
        int npage = Integer.parseInt(sPage);

        String sortorder = " order by fd_order";

        if (sSort.equals("c_名称")) {
            sortorder = " order by fd_mc " + sOrder;
        }
        System.out.println("========"+pno);

        String selesql = " select pk_fwqmc t_id,fd_mc c_名称,fd_lx c_类型,fd_bz c_备注 ";
        String fromsql = " from f_ld_fwqmc ";
        String withsql = "";
        String ordersql = sortorder;
        String groupsql = "";

        String wheresql = "where pk_scld='" + onekeyid + "'";
        if (pno.equals("0")){
            wheresql+=" and fd_lx='服务区'";
        }
        if (pno.equals("1")){
            wheresql+=" and fd_lx='停车区'";
        }
        if (pno.equals("2")){
            wheresql+=" and fd_lx='加油站'";
        }
        if (pno.equals("3")){
            wheresql+=" and fd_lx='收费站'";
        }

        DBTools tmpdata = new DBTools();
        HashMap<String, String> hashmap = new HashMap<String, String>();
        hashmap.put("fd_WithSql".toLowerCase(), withsql);
        hashmap.put("fd_SearchSql".toLowerCase(), selesql);
        hashmap.put("fd_FromSql".toLowerCase(), fromsql);
        hashmap.put("fd_WhereSql".toLowerCase(), wheresql);
        hashmap.put("fd_OrderSql".toLowerCase(), ordersql);
        hashmap.put("fd_GroupSql".toLowerCase(), groupsql);

        int ntot = 0;
        long ltotNum = 0;
        List<Object> thisobj = null;


            ntot = DBOperator.countNum(fromsql, wheresql, ordersql, withsql,
                    groupsql);
            thisobj = tmpdata.makePageList(hashmap, npage, nrows, ntot);
            ltotNum = (long) ntot;

        DataGrid dg = new DataGrid();
        dg.setRows(thisobj);
        dg.setTotal(ltotNum);
        return dg;
    }



}
